package com.cll.learn.filter;

import com.alibaba.fastjson.JSONObject;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 描述信息:
 * 消费端使用的dubbo的过滤器
 * @author CLL
 * @version 1.0
 * @date 2020/10/9 16:40
 */
@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER})
public class TransportIpFilter implements Filter {

    private static final Logger LOGGER = LoggerFactory.getLogger(TransportIpFilter.class);

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        DubboTraffic.saveFrom(WebRequestHolder.getCurrentRequest());
        LOGGER.info("===>>> invoker = {}", JSONObject.toJSONString(invoker));
        LOGGER.info("===>>> invocation = {}", JSONObject.toJSONString(invocation));
        return invoker.invoke(invocation);
    }
}
